package com.tie.jun.ge.xxljob.repostory.impl;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tie.jun.ge.xxljob.domain.TaskManagerDO;
import com.tie.jun.ge.xxljob.domain.TaskManagerPO;
import com.tie.jun.ge.xxljob.mapper.TaskManagerMapper;
import com.tie.jun.ge.xxljob.repostory.TaskManagerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @program: springboot
 * @description: TaskManagerRepository实现类
 * @author: getiejun
 * @create: 2025-11-05 23:59
 **/
@Repository
public class TaskManagerRepositoryImpl extends ServiceImpl<TaskManagerMapper, TaskManagerPO> implements TaskManagerRepository {

    @Autowired
    private TaskManagerMapper taskManagerMapper;

    @Override
    public void save(TaskManagerDO taskManagerDO) {
        TaskManagerPO taskManagerPO = new TaskManagerPO(taskManagerDO);
        taskManagerPO.setId(IdUtil.getSnowflakeNextId());
        taskManagerPO.setCreateBy(IdUtil.getSnowflakeNextId());
        taskManagerPO.setUpdateBy(IdUtil.getSnowflakeNextId());
        save(taskManagerPO);
    }

    @Override
    public List<TaskManagerDO> listAll() {
        QueryWrapper<TaskManagerPO> queryWrapper = new QueryWrapper<>();
        List<TaskManagerPO> list = taskManagerMapper.selectList(queryWrapper);
        return list.stream().map(TaskManagerPO::toDO).collect(Collectors.toList());
    }

    public static void main(String[] args) {
        long id = IdUtil.getSnowflakeNextId();
        Long a = id;
        System.out.println(a);
    }
}
